﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace yq.BLOB
{
    internal class Folder
    {
        /// <summary>
        /// 文件夹信息字典
        /// </summary>
        public static Dictionary<string, yq.BLOB.SysFileServer> FolderDic = new Dictionary<string, yq.BLOB.SysFileServer>();

        /// <summary>
        /// 默认服务器地址
        /// </summary>
        public static string BlobServer = "";


         static Folder()
        {
            BlobServer = cn.Util.WebConfig.AppSetting<string>("BlobServer");
            var web = new cn.Util.WebApi();

            //初始化文件夹
            var msg = web.To(BlobServer + "Main/Get");
            FolderDic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, yq.BLOB.SysFileServer>>(msg.Text);
           
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="folderId"></param>
        /// <returns></returns>
        public static bool Add(string folderId)
        {
            var web = new cn.Util.WebApi();
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("folderId", folderId);
            var msg = web.To(BlobServer + "Main/Add", "", parameters);
            var server = Newtonsoft.Json.JsonConvert.DeserializeObject<yq.BLOB.SysFileServer>(msg.Text);

            //添加到字典
            FolderDic.Add(folderId, server);

            return msg.IsOk;
        }

        /// <summary>
        /// 是否存在区域
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static yq.BLOB.SysFileServer Get(string id)
        {
            if (FolderDic.ContainsKey(id))
            {
                return FolderDic[id];
            }
            else
            {
                return new yq.BLOB.SysFileServer() { IsLocd=false };
            }
        }


      

    }
}
